package secondStage.part4.字符流;

import java.io.*;

/**
 * @ClassName: [ZiFuLiu1]
 * @Description: 字符流的抽象基类
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-04]
 * @Version: [v1.0]
 */
/*
3.4字符流中的编码解码问题
字符流抽象基类
    ●Reader:字符输入流的抽象类
    ●Writer: 字符输出流的抽象类
字符流中和编码解码问题相关的两个类:
    ●InputStreamReader
    ●OutputStreamWriter
*/
public class ZiFuLiu1 {
    public static void main(String[] args) throws IOException {
        //OutputStreamWriter(OutputStream out)创建一个使用默认字符编码的OutputStreamWriter
//        FileOutputStream fos = new FileOutputStream("java.txt");
//        OutputStreamWriter osw = new OutputStreamWriter(fos);
        OutputStreamWriter ows = new OutputStreamWriter(new FileOutputStream("java.txt"));
//        OutputStreamWriter ows = new OutputStreamWriter(new FileOutputStream("java.txt"),"UTF-8");
//        OutputStreamWriter ows = new OutputStreamWriter(new FileOutputStream("java.txt"),"GBK");
        ows.write("中国");
        ows.close();

        //读取数据
        InputStreamReader isr = new InputStreamReader(new FileInputStream("java.txt"));
//        InputStreamReader isr = new InputStreamReader(new FileInputStream("java.txt"),"UTF-8");
//        InputStreamReader isr = new InputStreamReader(new FileInputStream("java.txt"),"GBK");
        int ch;
        while ((ch=isr.read())!=-1){
            System.out.println((char)ch);
        }
        isr.close();
    }
}
